﻿#include "reviseaifaceform.h"
#include "ui_reviseaifaceform.h"
#include "httpclient.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QMessageBox>
ReviseAiFaceForm::ReviseAiFaceForm(const AiFaceParam &param, const QString &ip, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ReviseAiFaceForm),
    m_param(param),
    m_ip(ip)
{
    ui->setupUi(this);
    this->initform();
}

ReviseAiFaceForm::~ReviseAiFaceForm()
{
    delete ui;
}
void ReviseAiFaceForm::initform()
{
    this->setWindowTitle("修改员工信息");
    ui->led_name->setText(m_param.name);
    ui->led_work_number->setText(m_param.work_number);
    ui->led_id_number->setText(m_param.id_number);
    ui->led_phone->setText(m_param.phone);
    ui->led_department->setText(m_param.department);
    ui->led_memo_fir->setText(m_param.memo_fir);
    ui->led_memo_sec->setText(m_param.memo_sec);
    ui->led_memo_thi->setText(m_param.memo_thi);
}

void ReviseAiFaceForm::on_btn_sure_clicked()
{
    QJsonObject body;
    body.insert("name", ui->led_name->text());
    body.insert("work_number", ui->led_work_number->text());
    body.insert("id_number", ui->led_id_number->text());
    body.insert("phone", ui->led_phone->text());
    body.insert("department", ui->led_department->text());
    body.insert("memo_fir", ui->led_memo_fir->text());
    body.insert("memo_sec", ui->led_memo_sec->text());
    body.insert("memo_thi", ui->led_memo_thi->text());
    QJsonDocument jsondoc;
    jsondoc.setObject(body);
    QString request = QString(jsondoc.toJson(QJsonDocument::Compact));
    QString request_path = QString("http://%1:8800/api/face/%2").arg(m_ip).arg(m_param.id);
    HttpClient(request_path).success([this](const QString & response)
    {
        if(QMessageBox::information(nullptr, tr("通知"), tr("修改成功"), QMessageBox::Ok, QMessageBox::NoButton))
        {
            emit sig_clear();
            this->close();
        }
    }).json(request).put();
}

